#include "StdAfx.h"
#include "constant_surface.h"


constant_surface::constant_surface(void)
{
	rise = 0.0f;
	width_percent = 1.0f;
}


constant_surface::~constant_surface(void)
{
}

void constant_surface::draw(float* start, float* end, float start_dist, float end_dist, float* delta)
{
	glBindTexture(GL_TEXTURE_2D, texture);

	float surface_normal[3]={0.0f, 1.0f, 0.0f};
	float start_phrase = phrase + start_dist/cycle;
	float end_phrase = phrase + end_dist/cycle;

	glBegin(GL_QUADS);

	glNormal3fv(surface_normal);
	glTexCoord2f(1.0f, start_phrase);
	glVertex3f(start[0] + width_percent*delta[0], start[1] + rise, start[2] + width_percent*delta[2]);
	
	glNormal3fv(surface_normal);
	glTexCoord2f(0.0f, start_phrase);
	glVertex3f(start[0] - width_percent*delta[0], start[1]+ rise, start[2] - width_percent*delta[2]);
	
	glNormal3fv(surface_normal);
	glTexCoord2f(0.0f, end_phrase);
	glVertex3f(end[0] - width_percent*delta[0], end[1]+ rise, end[2] - width_percent*delta[2]);

	glNormal3fv(surface_normal);
	glTexCoord2f(1.0f, end_phrase);
	glVertex3f(end[0] + width_percent*delta[0], end[1]+ rise, end[2] + width_percent*delta[2]);


	glEnd();

}

void constant_surface::draw_corner(float *previous_point, float *cur_point, 
								float* previous_delta, float *cur_delta, 
								float* center_point, float corner_radius)
{
	glBindTexture(GL_TEXTURE_2D, texture);

	float surface_normal[3]={0.0f, 1.0f, 0.0f};
	float corner_phrase_begin = phrase;
	float corner_phrase_end = phrase + corner_radius*2/cycle;
	float corner_phrase_center = (corner_phrase_begin + corner_phrase_end)/2;
	

	glBegin(GL_TRIANGLE_FAN);

	glNormal3fv(surface_normal);
	glTexCoord2f(0.5f, corner_phrase_center);
	glVertex3f(center_point[0] , center_point[1] + rise, center_point[2]);
	
	glNormal3fv(surface_normal);
	glTexCoord2f(0.0f, corner_phrase_end);
	glVertex3f(cur_point[0] - width_percent*cur_delta[0], 
		cur_point[1] - width_percent*cur_delta[1] + rise, 
		cur_point[2] - width_percent*cur_delta[2]);

	glNormal3fv(surface_normal);
	glTexCoord2f(1.0f, corner_phrase_end);
	glVertex3f(cur_point[0] + width_percent*cur_delta[0], 
		cur_point[1] + width_percent*cur_delta[1] + rise, 
		cur_point[2] + width_percent*cur_delta[2]);
	

	glNormal3fv(surface_normal);
	glTexCoord2f(1.0f, corner_phrase_begin);
	glVertex3f(previous_point[0] + width_percent*previous_delta[0], 
		previous_point[1] + width_percent*previous_delta[1] + rise, 
		previous_point[2] + width_percent*previous_delta[2]);

	glNormal3fv(surface_normal);
	glTexCoord2f(0.0f, corner_phrase_begin);
	glVertex3f(previous_point[0] - width_percent*previous_delta[0], 
		previous_point[1] - width_percent*previous_delta[1] + rise, 
		previous_point[2] - width_percent*previous_delta[2]);

	glNormal3fv(surface_normal);
	glTexCoord2f(0.0f, corner_phrase_end);
	glVertex3f(cur_point[0] - width_percent*cur_delta[0], 
		cur_point[1] - width_percent*cur_delta[1] + rise, 
		cur_point[2] - width_percent*cur_delta[2]);

	glEnd();


}